import Component from "../component";

// import Brand from "./brand";

class MainJumpInfo extends Component {
  brand_type: '3' | '4' | 'WECHAT_CHANNELS' | undefined = undefined;
  page_type: 'PAGE_TYPE_WECHAT_MINI_PROGRAM' | 'PAGE_TYPE_WECHAT_CANVAS' | 'PAGE_TYPE_WECHAT_CHANNELS_WATCH_LIVE' = 'PAGE_TYPE_WECHAT_MINI_PROGRAM'
  // page_type: 'PAGE_TYPE_WECHAT_MINI_PROGRAM' | 'PAGE_TYPE_WECHAT_CANVAS' = 'PAGE_TYPE_WECHAT_MINI_PROGRAM';
  value = {
    page_type: 'PAGE_TYPE_WECHAT_MINI_PROGRAM',
    page_id: undefined,
    mini_program_id: undefined,
    mini_program_path: '',
    override_canvas_head_option: undefined

  }
  optional:any = [];
  get label() {
    if (this.value.page_type === 'PAGE_TYPE_WECHAT_CHANNELS_WATCH_LIVE') return '视频号';
    return this.value.page_type === 'PAGE_TYPE_WECHAT_CANVAS' ? '原生推广页' : '微信小程序'
  }

  page_spec = {
    'PAGE_TYPE_WECHAT_MINI_PROGRAM': 'wechat_mini_program_spec',
    'PAGE_TYPE_WECHAT_CANVAS': 'wechat_canvas_spec',
    'PAGE_TYPE_WECHAT_CHANNELS_WATCH_LIVE': ''
  }

  back(componentValue: any) {
    this.value.page_type = componentValue.page_type;
    const key = (this.page_spec as any)[componentValue.page_type];
    const spec = componentValue['page_spec'] ? (componentValue['page_spec'][key] || {}) : {};
    this.value.mini_program_id = spec.mini_program_id;
    this.value.mini_program_path = spec.mini_program_path;
    this.value.override_canvas_head_option = spec.override_canvas_head_option;
    this.value.page_id = spec.page_id;
  }

  query(options: any = {}) {
    const page_type = options.page_type || this.value.page_type;

    let page_spec = {};
    if (page_type == 'PAGE_TYPE_WECHAT_CANVAS') {
      page_spec = {
        wechat_canvas_spec: {
          override_canvas_head_option: options.override_canvas_head_option || this.value.override_canvas_head_option,
          page_id: this.value.page_id
        }
      }
    }
    if (page_type == 'PAGE_TYPE_WECHAT_MINI_PROGRAM') {
      page_spec = {
        wechat_mini_program_spec: {
          backup_option: "BACKUP_OPTION_DEFAULT_OFF",
          mini_program_id: this.value.mini_program_id,
          mini_program_path: this.value.mini_program_path
        }
      }
    }
    return {
      page_type,
      page_spec
    }
  }

}

export default MainJumpInfo;
